export default {
    data() {
      return {
        search: {}, // 搜索数据
        _search: {}, // 搜索初始数据
        listLoading: true,
        listFinished: false,
        pageInfo: {
          page: 1,
          pageSize: 10
        },
        _pageInfo: {},
        listData: [],

        //
        isLoading: false
      };
    },

    created() {
      this.remarkData(); // 记录初始化数据
    },
    methods: {
      listLoad() {
        this.listLoading = true;
        this.$utils.throttle(this.handleLoad);
      },

      handleLoad() {
        this.onload()
          .then((res) => {
            this.listLoading = false;
            this.isLoading = false;
            const count = res.count;

            const len = this.listData.length;
            if (count <= len || (res.list && res.list.length === 0)) {
              this.listFinished = true;
              return;
            }
            this.listFinished = false;
            this.pageInfo.page++;
          })
          .catch(() => {
            this.listLoading = false;
            this.listFinished = true;
            this.isLoading = false;
          });
      },
      remarkData() {
        this._pageInfo = this.$utils.deep(this.pageInfo);
      },

      resetSearch() {
        this.pageInfo = this.$utils.deep(this._pageInfo);
        this.listData = [];
        this.listLoad();
      },

      listRefresh() {
        this.pageInfo = this.$utils.deep(this._pageInfo);
        this.listLoad();
      }
    }
  };
